<template>
  <div id="app">
    <el-select v-model="languageValue" @change="changeLanguage" :placeholder="$t('message.requireSelect')" class="select-lang">
      <el-option
        v-for="item in languageOptions"
        :key="item.value"
        :label="item.label"
        :value="item.value">
      </el-option>
    </el-select>

    <router-view/>
  </div>
</template>

<script>
export default {
  data() {
    return {
      languageValue: '',
      languageOptions: [],
    }
  },
  created() {

    if (this.$i18n.locale == 'zh') {
      this.languageValue = '中文简体';
      this.languageOptions = [{value: 'en', label: 'English'}]
    } else {
      this.languageValue = 'English';
      this.languageOptions = [{value: 'zh', label: '中文简体'}]
    }
  },
  methods: {
    // 多语言切换
    changeLanguage(type) {
      console.log(type);

      localStorage.setItem('locale', type)
      this.$i18n.locale = type;
      if (this.$i18n.locale == 'zh') {
        this.languageValue = '中文简体';
        this.languageOptions = [{value: 'en', label: 'English'}]
      } else {
        this.languageValue = 'English';
        this.languageOptions = [{value: 'zh', label: '中文简体'}]
      }
    },
  }
}

</script>

<style>
html,
body {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 0px;
  margin: 0px;
}

#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  width: 100%;
  height: 100%;
}

.select-lang {
  width: 120px;
  position: absolute;
  right: 0;
  top: 0;
}

.select-lang input {
  background-color: transparent;
  border: none;
  color: white;
}
</style>
